package com.wjj.web.runner;

import cn.hutool.core.net.Ipv4Util;
import cn.hutool.core.util.StrUtil;
import com.wjj.common.core.utils.SpringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * @author wujunjie
 * @version 1.0
 * @date 2025/08/07 - 9:46
 */
@Order
@Component
public class PrintApiDocPathRunner implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        String flag = SpringUtils.getProperty("springdoc.api-docs.enabled");
        if ("true".equals(flag)) {
            InetAddress localHost = InetAddress.getLocalHost();
            String ip = localHost.getHostAddress();
            String port = SpringUtils.getProperty("server.port");
            String contextPath = SpringUtils.getProperty("server.servlet.context-path");
            contextPath = StrUtil.SLASH.equals(contextPath) ? "" : contextPath;
            String info = StrUtil.format( "接口文档地址：http://{}:{}{}/v3/api-docs", ip, port, contextPath);
            System.out.println(info);
        }
    }
}
